# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=tootik
pkgver=0.5.10
pkgrel=0
pkgdesc="Federated nanoblogging service with Gemini frontend"
url="https://github.com/dimkr/tootik"
# armhf, armv7, x86, s390x: tests fail
arch="all !armhf !armv7 !x86 !s390x"
license="Apache-2.0"
depends="openssl"
makedepends="go sqlite-dev"
install="$pkgname.pre-install"
pkgusers="tootik"
pkggroups="tootik"
subpackages="$pkgname-openrc"
source="https://github.com/dimkr/tootik/archive/refs/tags/$pkgver/tootik-$pkgver.tar.gz
	tootik.initd
	tootik.confd

	rate-limiting.patch
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

export CGO_ENABLED=1
export _GOTAGS="libsqlite3"

build() {
	local _goldflags="
		-X github.com/dimkr/tootik/buildinfo.Version=$pkgver
		"

	go generate -v ./migrations
	go vet -v -tags "$_GOTAGS" ./...
	go build -v -ldflags "$_goldflags" -tags "$_GOTAGS" ./cmd/tootik
}

check() {
	./tootik --version

	go test -v -tags "$_GOTAGS" ./...
}

package() {
	install -Dm755 tootik -t "$pkgdir"/usr/bin/
	install -dm750 -o tootik -g tootik "$pkgdir"/var/lib/tootik
	install -dm750 -o tootik -g tootik "$pkgdir"/etc/tootik

	install -Dm755 "$srcdir"/tootik.initd "$pkgdir"/etc/init.d/tootik
	install -Dm644 "$srcdir"/tootik.confd "$pkgdir"/etc/conf.d/tootik
}

sha512sums="
ec1402c20f94d5e15b40f4987add98023ce83955f836d1890019609359a11752cdf88a3439ded8ac0af362ee3d550217ddc13e7027b041ecba688010cc8e30ae  tootik-0.5.10.tar.gz
6986ad0ffb5c7d994f345124e45685995e08457f3efdf10ed502ade9c7a4e66c38b6ad8dd375cbad9009313b2ad0a3fe771ed7a254110dd757dee4e8a25dae0e  tootik.initd
37839cb7ed6164555c650dec578bde8006bfc88da5fbebd05e69b3ef10eaeb8e5c1ad06a2e5c1e705fb77dd26d2e604d9c512cc72fd3e18d8b6fda2d6489a6cf  tootik.confd
2db496a69029f297fe9ea4b2389881cc8ea168806eac0a12b3a29ca545abe7da580c710cac86db47071be534ffaf96ede95f38f47a5fe7085ae625e9ec3d3ff2  rate-limiting.patch
"
